package com.tour.controller;


import com.tour.config.ResponseWrapper;
import com.tour.entity.Story;
import com.tour.service.impl.StoryServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lel
 * @since 2021-04-10
 */
@RestController
@RequestMapping("/app/story")
@Api(tags = "红医故事管理")
public class StoryController {

    @Autowired
    StoryServiceImpl storyService;

    @ApiOperation("增加故事")
    @PostMapping("/addStory")
    public ResponseWrapper addStory(@RequestBody Story story){
        ResponseWrapper wrapper = storyService.addStory(story);
        return wrapper;
    }

    @ApiOperation("删除故事")
    @ApiImplicitParam(name = "storyId",value = "故事id")
    @DeleteMapping("/deleteStory")
    public ResponseWrapper deleteStory(@RequestParam(name="storyId")Integer storyId){
        ResponseWrapper wrapper = storyService.deleteStory(storyId);
        return wrapper;
    }

    @ApiOperation("修改故事")
    @PutMapping("/updateStory")
    public ResponseWrapper updateStory(@RequestBody Story story){
        ResponseWrapper wrapper = storyService.updateStory(story);
        return wrapper;
    }

    @ApiOperation("查询一个红色故事")
    @ApiImplicitParam(name = "storyId",value = "故事id")
    @GetMapping("/findOneStory")
    public ResponseWrapper findOneStory(@RequestParam(name = "storyId")Integer storyId){
        ResponseWrapper wrapper = storyService.findOneStory(storyId);
        return wrapper;
    }

    @ApiOperation("查询所有或者模糊查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "故事名称"),
            @ApiImplicitParam(name = "pageSize",value = "每页显示条数",defaultValue = "10"),
            @ApiImplicitParam(name = "pageNum",value = "当前页码数",defaultValue = "1")
    })
    @GetMapping("/findStory")
    public ResponseWrapper findStory(@RequestParam(name = "name",required = false)String name,
                                     @RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize,
                                     @RequestParam(name = "pageNum",defaultValue = "1")Integer pageNum){
        ResponseWrapper wrapper = storyService.findStory(name, pageSize, pageNum);
        return wrapper;
    }
}

